﻿<UserControl x:Class="IssueVision.Client.UserMaintenance"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:cmd="clr-namespace:GalaSoft.MvvmLight.Command;assembly=GalaSoft.MvvmLight.Extras.SL4"
    xmlns:dat="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data.Input"
    xmlns:common="clr-namespace:IssueVision.Common;assembly=IssueVision.Common"
    Loaded="UserControl_Loaded" Unloaded="UserControl_Unloaded"
    mc:Ignorable="d" d:DesignWidth="640" d:DesignHeight="480">
    
    <UserControl.Resources>
        <common:BooleanToVisibilityConverter x:Key="booleanToVisibilityConverter"/>
    </UserControl.Resources>
    
    <Grid x:Name="LayoutRoot">
        <Grid.RowDefinitions>
            <RowDefinition Height="1*" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>
        <ScrollViewer Grid.Row="0" Grid.Column="0"
                      VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Disabled">
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto" />
                    <ColumnDefinition Width="*" />
                    <ColumnDefinition Width="Auto" />
                    <ColumnDefinition Width="*" />
                </Grid.ColumnDefinitions>
                <TextBlock Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="4"
                           FontWeight="Bold" Margin="4" 
                           Text="User Info" />
                <TextBlock Grid.Row="1" Grid.Column="0"
                           VerticalAlignment="Center" Margin="4" 
                           Text="User name" />
                <TextBox x:Name="userNameTextBox" Grid.Row="1" Grid.Column="1"
                         Margin="4" MinHeight="25"
                         Visibility="{Binding Path=IsAddUser, Mode=OneWay, 
                                            Converter={StaticResource booleanToVisibilityConverter}}"
                         Text="{Binding Path=CurrentUser.Name, Mode=TwoWay,
                                     ValidatesOnExceptions=True, NotifyOnValidationError=True}"/>
                <ComboBox x:Name="comboBox_UserName" Grid.Row="1" Grid.Column="1" 
                          Margin="4" MinHeight="25"
                          Visibility="{Binding Path=IsUpdateUser, Mode=OneWay, 
                                             Converter={StaticResource booleanToVisibilityConverter}}"
                          ItemsSource="{Binding Path=AllUsersSource.View}"
                          SelectedItem="{Binding Path=CurrentUser, Mode=OneWay, ValidatesOnNotifyDataErrors=False}">
                    <ComboBox.ItemTemplate>
                        <DataTemplate>
                            <StackPanel>
                                <TextBlock Text="{Binding Path=DisplayName, ValidatesOnNotifyDataErrors=False}" />
                            </StackPanel>
                        </DataTemplate>
                    </ComboBox.ItemTemplate>
                </ComboBox>
                <TextBlock Grid.Row="2" Grid.Column="0"
                           VerticalAlignment="Center" Margin="4" 
                           Text="Email" />
                <TextBox x:Name="emailTextBox" Grid.Row="2" Grid.Column="1"
                         Margin="4" MinHeight="25"
                         Text="{Binding Path=CurrentUser.Email, Mode=TwoWay,
                                ValidatesOnExceptions=True, NotifyOnValidationError=True}"/>
                <TextBlock Grid.Row="1" Grid.Column="2"
                           VerticalAlignment="Center" Margin="4" 
                           Text="First name" />
                <TextBox x:Name="firstNameTextBox" Grid.Row="1" Grid.Column="3"
                         Margin="4" MinHeight="25"
                         Text="{Binding Path=CurrentUser.FirstName, Mode=TwoWay,
                                ValidatesOnExceptions=True, NotifyOnValidationError=True}"/>
                <TextBlock Grid.Row="2" Grid.Column="2"
                           VerticalAlignment="Center" Margin="4" 
                           Text="Last name" />
                <TextBox x:Name="lastNameTextBox" Grid.Row="2" Grid.Column="3"
                         Margin="4" MinHeight="25"
                         Text="{Binding Path=CurrentUser.LastName, Mode=TwoWay,
                                ValidatesOnExceptions=True, NotifyOnValidationError=True}"/>
                <TextBlock Grid.Row="3" Grid.Column="0" Grid.ColumnSpan="4"
                           FontWeight="Bold" Margin="4" 
                           Text="Security Info" />
                <TextBlock Grid.Row="4" Grid.Column="0"
                           VerticalAlignment="Center" Margin="4" 
                           Text="New Password" />
                <TextBlock x:Name="actualNewPasswordTextBlock"
                           Grid.Row="4" Grid.Column="1"
                           Margin="4" Height="25"
                           Text="{Binding Path=CurrentUser.ActualNewPassword, Mode=TwoWay,
                                       ValidatesOnNotifyDataErrors=False}"
                           Visibility="Collapsed"/>
                <PasswordBox x:Name="newPasswordPasswordBox"
                             Grid.Row="4" Grid.Column="1"
                             Margin="4" MinHeight="25"
                             Password="{Binding Path=CurrentUser.NewPassword, Mode=TwoWay,
                                        ValidatesOnExceptions=True, NotifyOnValidationError=True}"
                             PasswordChanged="newPasswordPasswordBox_PasswordChanged" />
                <StackPanel Grid.Row="5" Grid.Column="0">
                    <TextBlock Text="Confirm new" Margin="4,4,4,0" />
                    <TextBlock Text="password" Margin="4,0,4,4" />
                </StackPanel>
                <PasswordBox x:Name="newPasswordConfirmationPasswordBox" Grid.Row="5" Grid.Column="1"
                             Margin="4" Height="25"
                             Password="{Binding Path=CurrentUser.NewPasswordConfirmation, Mode=TwoWay,
                                                  ValidatesOnExceptions=True, NotifyOnValidationError=True}"/>
                <TextBlock Grid.Row="4" Grid.Column="2"
                           VerticalAlignment="Center" Margin="4" 
                           Text="User type" />
                <ComboBox Grid.Row="4" Grid.Column="3" 
                          Margin="4" MinHeight="25"
                          ItemsSource="{Binding Path=UserTypeEntries}"
                          SelectedItem="{Binding Path=CurrentUser.DisplayUserType, Mode=TwoWay,
                                                     ValidatesOnNotifyDataErrors=False}"/>
            </Grid>
        </ScrollViewer>
        <dat:ValidationSummary Grid.Row="1" Grid.Column="0"
                               Target="{Binding ElementName=LayoutRoot}" />
        <Button Grid.Row="2" Grid.Column="0"
                VerticalAlignment="Top" HorizontalAlignment="Right" 
                Width="75" Height="23" Margin="0,5,248,5" 
                Content="Add User"
                Command="{Binding Path=AddUserCommand}"/>
        <Button Grid.Row="2" Grid.Column="0"
                VerticalAlignment="Top" HorizontalAlignment="Right" 
                Width="75" Height="23" Margin="0,5,167,5" 
                Content="Delete User"
                Command="{Binding Path=RemoveUserCommand}"
                CommandParameter="{Binding SelectedItem, ElementName=comboBox_UserName, ValidatesOnNotifyDataErrors=False}"/>
        <Button Grid.Row="2" Grid.Column="0"
                VerticalAlignment="Top" HorizontalAlignment="Right" 
                Width="75" Height="23" Margin="0,5,86,5" 
                Content="Save"
                Command="{Binding Path=SubmitChangeCommand}"/>
        <Button  Grid.Row="2" Grid.Column="0"
                 VerticalAlignment="Top" HorizontalAlignment="Right"
                 Width="75" Height="23" Margin="0,5,5,5"
                 Content="Cancel"
                Command="{Binding Path=CancelChangeCommand}"/>
    </Grid>
</UserControl>
